package app.controller;

import app.entity.FacMom;
import app.entity.Pager;
import app.nbdevices.utils.ConvertUtil;
import app.nbdevices.vo.RegisterInfoVo;
import app.utils.BasePathCollector;
import app.utils.TimeUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.bean.Count;
import common.bean.DeviceBean;
import common.bean.EventLogBean;
import common.bean.FacDevInfo;
import common.dto.RealStatusDto;
import common.standard.table.*;
import common.standard.view.ViewNameEnum;
import common.util.RegionUtil;
import common.vo.WorkOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import refactor.entity.*;
import refactor.service.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.*;

import static org.apache.commons.lang3.StringUtils.isBlank;

/**
 * 侧边栏控制器，控制所有侧边栏功能
 *
 * @author 杨健
 * @since 2019/7/3 11:36
 */
@Slf4j
@Controller
public class NavigationController {

	private IApplyRecordService applyRecordService;

	@Autowired
	public void setApplyRecordService(IApplyRecordService applyRecordService) {
		this.applyRecordService = applyRecordService;
	}

	private IFacilityDeviceService facilityDeviceService;

	@Autowired
	public void setFacilityDeviceService(IFacilityDeviceService facilityDeviceService) {
		this.facilityDeviceService = facilityDeviceService;
	}

	private IEventLogService eventLogService;

	@Autowired
	public void setEventLogService(IEventLogService eventLogService) {
		this.eventLogService = eventLogService;
	}

	private IGdclService workOrderService;

	@Autowired
	public void setWorkOrderService(IGdclService workOrderService) {
		this.workOrderService = workOrderService;
	}

	private IGroupService groupService;

	@Autowired
	public void setGroupService(IGroupService groupService) {
		this.groupService = groupService;
	}

	private IFacMonitoringService facMonitoringService;

	@Autowired
	public void setFacMonitoringService(IFacMonitoringService facMonitoringService) {
		this.facMonitoringService = facMonitoringService;
	}

	private IFaultInfoService faultInfoService;

	@Autowired
	public void setFaultInfoService(IFaultInfoService faultInfoService) {
		this.faultInfoService = faultInfoService;
	}

	private IFacilityDeviceService facDevService;

	@Autowired
	public void setFacDevService(IFacilityDeviceService facDevService) {
		this.facDevService = facDevService;
	}

	private IOrganizationService organizationService;

	@Autowired
	public void setOrganizationService(IOrganizationService organizationService) {
		this.organizationService = organizationService;
	}

	private INewMateService newMateService;

	@Autowired
	public void setNewMateService(INewMateService newMateService) {
		this.newMateService = newMateService;
	}

	private IReadMeterService readMeterService;

	@Autowired
	public void setReadMeterService(IReadMeterService readMeterService) {
		this.readMeterService = readMeterService;
	}

	private IAllLogService allLogService;

	@Autowired
	public void setAllLogService(IAllLogService allLogService) {
		this.allLogService = allLogService;
	}

	@Autowired
	private IDeviceService devsvc;

	@Autowired
	private IFacilitiesService facilitiesService;



	/**
	 * 日期格式
	 */
	private static final String FORMAT = "yyyy-MM-dd";

	/**
	 * 设备信息展示
	 * @param model
	 * @param pageNum
	 * @param request
	 * @return
	 */
	@GetMapping("/2/devinfos")
	public String DeviceInfoShow(Model model, DeviceBean info,
								 @RequestParam(required = false, defaultValue = "1") Integer pageNum,
								 @RequestParam(required = false, defaultValue = "0")Integer facId,
								 @RequestParam(required = false, defaultValue = "0")Integer devId,
								 @RequestParam(required = false, defaultValue = "0")Integer modId,
								 @RequestParam(required = false, defaultValue = "")String condition,
								 HttpServletRequest request){

		IPage<Device> deviceIPage=devsvc.pageList(pageNum,modId,facId,devId,condition,info);
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		System.out.println(info);
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), new Pager(((int) deviceIPage.getTotal()), pageNum));
		List<Device> records = deviceIPage.getRecords();
		for(int i=0;i<records.size();i++){
			LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochMilli(records.get(i).getOnline()*1000), ZoneId.systemDefault());
			String format = time.format(ConvertUtil.getFormatter());
			records.get(i).setStandard(format);
		}
		model.addAttribute(ModelAttributeEnum.LIST.getAttributeName(), deviceIPage.getRecords());
		model.addAttribute(ModelAttributeEnum.INFO.getAttributeName(),info);
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(),BasePathCollector.getRequestUrl(request));
		return ViewNameEnum.DEVICE_INFO_SHOW.getViewName();
	}

	/**
	 * 设备添加
	 * @param model
	 * @param request
	 * @return
	 */
	@GetMapping("/2/devadd")
	public String DeviceAdd(Model model, HttpServletRequest request){
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		 return ViewNameEnum.DEVICE_ADD.getViewName();
	}

	/**
	 * 获取当前管理员用户可以获取的工单的派发与处理情况（该工单是故障工单，由系统自动派发）
	 *
	 * @param model model
     * @param workOrder 工单条件包装对象
	 * @param pageNum 当前页
	 * @param request request请求
	 * @return 返回到工单处理页面
	 */

	@GetMapping("/2/gdcl")
	public String workOrderProcess(Model model,
								   WorkOrderVo workOrder,
								   @RequestParam(required = false, defaultValue = "1") Integer pageNum,
								   HttpServletRequest request){

		IPage<Gdcl> gdclIPage = workOrderService.pageList(workOrder, RegionUtil.userRegion(request.getSession()), pageNum);

		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), new Pager(((int) gdclIPage.getTotal()), pageNum));
		model.addAttribute(ModelAttributeEnum.LIST.getAttributeName(), gdclIPage.getRecords());
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(), BasePathCollector.getRequestUrl(request));
		model.addAttribute(ModelAttributeEnum.YCL.getAttributeName(), workOrder.getYcl());
		model.addAttribute(ModelAttributeEnum.WCL.getAttributeName(), workOrder.getWcl());
		model.addAttribute(ModelAttributeEnum.CONDITION.getAttributeName(), workOrder.getCondition());

		return ViewNameEnum.GDCL.getViewName();
	}
	

	/**
	 * 逻辑区域信息及其管理
     *
	 * @param model model
	 * @param pageNum 当前页码
	 * @param request http请求
	 * @return 返回到区域视图
	 */
	@RequestMapping("/2/logicarea")
	public String logicArea(Model model,
							@RequestParam(required = false, defaultValue = "1") Integer pageNum,
							HttpServletRequest request){

		IPage<Group> groupIPage = groupService.pageList(RegionUtil.userRegion(request.getSession()), pageNum);

		Pager pager = new Pager(((int) groupIPage.getTotal()), pageNum);

		model.addAttribute(ModelAttributeEnum.LIST.getAttributeName(), groupIPage.getRecords());
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(), BasePathCollector.getRequestUrl(request));

		return ViewNameEnum.LOGIC_AREA.getViewName();
	}

	/**
	 * 同步获取显示在首页上的开锁临时申请与未处理条数，已绑定设施和未绑定设施的条数
     *
	 * @param model 模型
	 * @return 返回至首页
	 */
	@RequestMapping(value="/2/index",method={RequestMethod.POST,RequestMethod.GET})
	public String indexGet(HttpServletRequest request, Model model) {
		Integer regionId = RegionUtil.userRegion(request.getSession());



		//取临时申请处理与未处理
        int tempApplyHandledCount = eventLogService.countAllCasualApplicationByRegionId(regionId);
		
		int applyNotHandledCount = eventLogService.countAllCasualApplicationByRegionIdNotHandle(regionId);
		
		//取设施未绑定与绑定总数
		QueryWrapper<FacilityDevice> deviceQueryWrapper = new QueryWrapper<FacilityDevice>().eq(FacilityDeviceFieldEnum.DEVCODE.getFieldName(), "").eq(FacilityDeviceFieldEnum.REGIONID.getFieldName(), regionId);

		int deviceBindTotalCount = facilityDeviceService.count(deviceQueryWrapper);
		QueryWrapper<FacilityDevice> deviceQueryWrapper1=new QueryWrapper<FacilityDevice>().eq(FacilityDeviceFieldEnum.REGIONID.getFieldName(), regionId);
		//deviceQueryWrapper.eq();
		int deviceNotBindCount = facilityDeviceService.count(deviceQueryWrapper1);

		Count count = new Count();
		count.setTotal(tempApplyHandledCount);
		count.setNum(applyNotHandledCount);
		
		count.setTotal1(deviceNotBindCount);
		count.setNum1(deviceBindTotalCount);
		
		//放入model中
		model.addAttribute(ModelAttributeEnum.COUNT.getAttributeName(), count);
		
		//获取故障列表，限5条
		Page<FaultInfo> faultInfoPage = new Page<>(1, 5);
		QueryWrapper<FaultInfo> faultInfoQueryWrapper = new QueryWrapper<>();

		faultInfoQueryWrapper.eq("res", "0");
		List<FaultInfo> records = faultInfoService.page(faultInfoPage, faultInfoQueryWrapper).getRecords();

		// 放入model中
		model.addAttribute(ModelAttributeEnum.LIST_BUG.getAttributeName(), records);
		
		// 在model中放入basePath
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		
		return ViewNameEnum.INDEX.getViewName();
	}

    /**
     * 实时状态监测
     * @param data 数据
     * @param pageNum 当前页码
     * @param model 模型
     * @param request http请求
     * @return 跳转到实时状态监测视图
     */
	@RequestMapping(value="/2/realtime",method={RequestMethod.POST,RequestMethod.GET})
	public String realTime(FacMom data,
						   @RequestParam(required = false, defaultValue = "1") Integer pageNum,
						   Model model,
						   HttpServletRequest request) throws ParseException {

		Integer regionId = RegionUtil.userRegion(request.getSession());
		IPage<FacMonitoring> facMonitoringIPage = facMonitoringService.pageList(data, regionId, pageNum);

		List<FacMonitoring> records = facMonitoringIPage.getRecords();

		//获取读数
		List<Integer> eleRes=new ArrayList<>();
		List<Integer> waterRes=new ArrayList<>();
		List<Integer> yanganRes=new ArrayList<>();
		List<Integer> menjinRes=new ArrayList<>();
		for(FacMonitoring fm:records){
			if(StringUtils.isNumeric(fm.getDevId())){
				if(fm.getModName().equals("电表")){
					eleRes.add(Integer.parseInt(fm.getDevId().trim()));
				}
				if(fm.getModName().equals("水表")){
					waterRes.add(Integer.parseInt(fm.getDevId().trim()));
				}
				if(fm.getModName().equals("烟感")){
					yanganRes.add(Integer.parseInt(fm.getDevId().trim()));
				}
				if(fm.getModName().equals("门禁盒子")){
					menjinRes.add(Integer.parseInt(fm.getDevId().trim()));
				}
			}
		}

		HashMap<String, RealStatusDto> readData = devsvc.getreadData(eleRes, waterRes, menjinRes,yanganRes);

		for(int i=0;i<readData.size();i++){
			records.get(i).setEventEle(readData.get(records.get(i).getDevId()).getRead());
			LocalDateTime time1 = LocalDateTime.ofEpochSecond(readData.get(records.get(i).getDevId()).getNowTime(),
					0, ZoneOffset.ofHours(8));
			records.get(i).setFacNetName(time1.format(ConvertUtil.getFormatters()));
		}


		Pager pager = new Pager(((int) (facMonitoringIPage.getTotal())), pageNum);

		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		System.out.println("BasePathCollector.getBasePathWithoutPort(request)"+BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.FACILITY.getAttributeName(), records);
	//	System.out.println("data"+data);
		model.addAttribute(ModelAttributeEnum.DATA.getAttributeName(), data);
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(),BasePathCollector.getRequestUrl(request));
		System.out.println("BasePathCollector.getRequestUrl(request)"+BasePathCollector.getRequestUrl(request));

		return ViewNameEnum.MONITOR.getViewName();
	}

	/**
	 * 查看设备绑定情况
	 *
	 * @param info 前台数据信息
	 * @param pageNum 当前页码
	 * @param model 模型
	 * @param request request请求
	 * @return 返回至facdev视图
	 */
	@GetMapping("/2/devbindinfo")
	public String devBindInfo(FacDevInfo info,
							  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
							  Model model,
							  HttpServletRequest request){

		IPage<FacilityDevice> facDevIPage = facDevService.pageList(info, RegionUtil.userRegion(request.getSession()), pageNum);

		Pager pager = new Pager(((int) facDevIPage.getTotal()), pageNum);

		model.addAttribute(ModelAttributeEnum.FACILITY_DEVICE.getAttributeName(), facDevIPage.getRecords());
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.INFO.getAttributeName(),info);
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(),BasePathCollector.getRequestUrl(request));

		return ViewNameEnum.FACILITY_DEVICE.getViewName();
	}

	/**
	 * 临时申请操作
	 *
	 * @param pageNum 当前页码
	 * @param agreeCheckbox 选择框
	 * @param condition SQL条件
	 * @param startTime 开始时间
	 * @param endTime 结束时间
	 * @param model 模型
	 * @param request request请求
	 * @return 返回到临时申请视图
	 * @throws ParseException 转换异常
	 */
	@RequestMapping("/2/applyrecord")
	public String applyRecord(@RequestParam(value="pageNum",defaultValue="1")Integer pageNum,
							  @RequestParam(value="jj",defaultValue="")String agreeCheckbox,
							  @RequestParam(value="condition",defaultValue="")String condition,
							  @RequestParam(value="f",defaultValue="")String startTime,
							  @RequestParam(value="t",defaultValue="")String endTime,
							  Model model,
							  HttpServletRequest request) throws ParseException{
		Integer regionId = RegionUtil.userRegion(request.getSession());

		//获取一周前的00点
		Date startTimeWeekAgo;
		if (isBlank(startTime)) {
			long weekEarlier = TimeUtils.getNowDateLong()-( 7*3600*24*1000);
			//将时间转换成当天00点的date类型
			String weekEarlierStr = TimeUtils.formatTime(weekEarlier, FORMAT);
			startTime = weekEarlierStr;
			weekEarlierStr += " 00:00:00";
			startTimeWeekAgo = TimeUtils.StringToDate(weekEarlierStr, "yyyy-MM-dd HH:mm:ss");
		} else {
			startTimeWeekAgo = TimeUtils.StringToDate(startTime, FORMAT);
		}
		
		Date endTimeFormat = isBlank(endTime) ? TimeUtils.getNowDate() : TimeUtils.StringToDate(endTime, FORMAT);

		long time1 = startTimeWeekAgo.getTime();
		long time = endTimeFormat.getTime();
		//.ge(ApplyRecordFieldEnum.STARTTIME.getFieldName(), startTimeWeekAgo.getTime())   //去掉对开始时间的比较  只比较结束时间  当前时间大于结束时间  则无效
		QueryWrapper<ApplyRecord> applyRecordQueryWrapper = new QueryWrapper<ApplyRecord>()
				.ge(ApplyRecordFieldEnum.ENDTIME.getFieldName(), endTimeFormat.getTime())
				.eq(ApplyRecordFieldEnum.REGIONID.getFieldName(), regionId);
		if (!StringUtils.isEmpty(agreeCheckbox)) {
			applyRecordQueryWrapper.eq(ApplyRecordFieldEnum.RES.getFieldName(), "0");
		}
		if (!StringUtils.isEmpty(condition)) {
			applyRecordQueryWrapper.like(ApplyRecordFieldEnum.FACAREA.getFieldName(), condition);
		}

		Pager pager = new Pager(applyRecordService.count(applyRecordQueryWrapper), pageNum);

		List<ApplyRecord> list = applyRecordService.list(applyRecordQueryWrapper);

		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(),pager);
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(), BasePathCollector.getRequestUrl(request));
		model.addAttribute(ModelAttributeEnum.AGREE_CHECK.getAttributeName(), agreeCheckbox);
		model.addAttribute(ModelAttributeEnum.CONDITION.getAttributeName(), condition);
		model.addAttribute(ModelAttributeEnum.TIME_BEFORE.getAttributeName(), startTime);
		model.addAttribute(ModelAttributeEnum.TIME_NOW.getAttributeName(), endTime);
		model.addAttribute(ModelAttributeEnum.LIST.getAttributeName(), list);
		
		return ViewNameEnum.APPLY_RECORD.getViewName();
	}

	/**
	 * 事件日志
	 *
	 * @param info SQL条件
	 * @param pageNum 当前页码
	 * @param model 模型
	 * @param request request请求
	 * @return 返回至事件日志视图
	 */
	@RequestMapping("/2/eventlog")
	public String eventLog(EventLogBean info,
						   @RequestParam(required = false, defaultValue = "1") Integer pageNum,
						   Model model,
						   HttpServletRequest request) throws ParseException {

		IPage<AllLog> allLogIPage = allLogService.pageList(info, RegionUtil.userRegion(request.getSession()), pageNum);

		Pager pager = new Pager(((int) allLogIPage.getTotal()), pageNum);
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(), BasePathCollector.getRequestUrl(request));
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.DATA.getAttributeName(), info);
		model.addAttribute(ModelAttributeEnum.RES.getAttributeName(), allLogIPage.getRecords());

		return ViewNameEnum.EVENT_LOG.getViewName();
	}

	/**
	 * 施工单位及人员
	 *
	 * @param pageNum 当前页码
	 * @param model model
	 * @param request request请求
	 * @return 返回至施工单位视图
	 */
	@GetMapping("/2/unitandstaff")
	public String unitAndStaff(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
							   Model model,
							   HttpServletRequest request) {
		IPage<Organization> organizationIPage = organizationService.pageList(RegionUtil.userRegion(request.getSession()), pageNum);
		Pager pager = new Pager(((int) organizationIPage.getTotal()), pageNum);

		model.addAttribute(ModelAttributeEnum.ORGANIZATIONS.getAttributeName(), organizationIPage.getRecords());
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));

		return ViewNameEnum.BUILDER_MANAGE.getViewName();
	}
	
	/**
	 * 施工单位人员添加申请
	 *
	 * @param pageNum 当前页码
	 * @param companyId 公司id
	 * @param model 模型
	 * @param request request请求
	 * @return 返回至视图
	 */
	@GetMapping("/2/jointounit")
	public String joinToUnit(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
							 Integer companyId,
							 Model model,
							 HttpServletRequest request){

		QueryWrapper<NewMate> newMateQueryWrapper = new QueryWrapper<>();
		newMateQueryWrapper.eq(NewMateFieldEnum.REGIONID.getFieldName(), RegionUtil.userRegion(request.getSession()))
				.eq(NewMateFieldEnum.ORGANIZATIONID.getFieldName(), companyId);

		Page<NewMate> newMatePage = new Page<>(pageNum, PageEnum.PAGE_SIZE.getValue());
		List<NewMate> appliers = newMateService.page(newMatePage, newMateQueryWrapper).getRecords();

		List<NewMate> com = newMateService.list(newMateQueryWrapper);

		Set<NewMate> comSet=new TreeSet<>(com);
		Pager pager = new Pager(com.size(), pageNum);

		model.addAttribute(ModelAttributeEnum.COMPANIES.getAttributeName(), comSet);
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.RES.getAttributeName(), appliers);
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.COMPANY.getAttributeName(), companyId);
		model.addAttribute(ModelAttributeEnum.CURL.getAttributeName(), BasePathCollector.getRequestUrl(request));

		return ViewNameEnum.BUILDER_MAN.getViewName();
	}

	/**
	 * 远程抄表
	 *
	 * @param pageNum 当前页码
	 * @param model 模型
	 * @param request request请求
	 * @return 返回至抄表视图
	 */
	@GetMapping("/2/copymeter")
	public String copyMeter(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
							Model model,
							HttpServletRequest request){
		Page<ReadMeter> readMeterPage = new Page<>(pageNum, PageEnum.PAGE_SIZE.getValue());

		//获取电表数据
		IPage<ReadMeter> page = readMeterService.page(readMeterPage);
		List<ReadMeter> records = page.getRecords();

		Pager pager = new Pager(((int) page.getTotal()), pageNum, PageEnum.PAGE_SIZE.getValue());
		model.addAttribute(ModelAttributeEnum.BASE_PATH.getAttributeName(), BasePathCollector.getBasePathWithoutPort(request));
		model.addAttribute(ModelAttributeEnum.PAGER.getAttributeName(), pager);
		model.addAttribute(ModelAttributeEnum.DATA.getAttributeName(), records);

		return ViewNameEnum.COPY_METER.getViewName();
	}

	/**
	 * 注销登录
	 *
	 * @param session session
	 * @param request request请求
	 * @return 重定向至登录页面
	 */
	@GetMapping("/logout")
	public String logOut(HttpSession session,HttpServletRequest request){
		session.invalidate();
		return "redirect:" + BasePathCollector.getBasePathWithoutPort(request) + "/login";
	}

}
